package m5_topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("192.168.126.130");
        cf.setUsername("admin");
        cf.setPassword("admin");
        Channel c = cf.newConnection().createChannel();

        //定义direct 类型交换机，
        c.exchangeDeclare("topic_log", BuiltinExchangeType.TOPIC);
        //发送消息，在消息上携带路由键
        while (true) {
            System.out.println("输入消息：");
            String msg=new Scanner(System.in).nextLine();
            System.out.println("请输入路由键：");
            String key=new Scanner(System.in).nextLine();
            c.basicPublish("topic_log",key,null,msg.getBytes());
        }
    }

}
